package com.cowin.sys.service.impl;

import com.cowin.sys.dao.TmVhcVehicleMapper;
import com.cowin.sys.model.TmVhcVehicle;
import com.cowin.sys.model.VehicleImpress;
import com.cowin.sys.model.vo.*;
import com.cowin.sys.service.TmVhcVehicleService;
import com.cowin.base.AbstractServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * Created by  on 2019/09/24.
 *
 * @author CodeGenerator
 */
@Slf4j
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class TmVhcVehicleServiceImpl extends AbstractServiceImpl<TmVhcVehicle> implements TmVhcVehicleService {

    public static final String SKYLIGHT = "Skylight";
    public static final String STEER = "Steer";
    public static final String HIGH_BRIGHT_FILM = "HighBrightFilm";
    public static final String EV = "Ev";
    @Resource
    private TmVhcVehicleMapper tmVhcVehicleMapper;

    @Override
    public List<TmVhcVehicle> searchHoldVehicle(HoldVehicle holdVehicle) {
        return tmVhcVehicleMapper.searchHoldVehicle(holdVehicle);
    }

    @Override
    public TmVhcVehicle findByVinNo(String vinNo) {
        return tmVhcVehicleMapper.findByVinNo(vinNo);
    }

    @Override
    public List<VehicleImpress> getSettingDict() {
        //颜色
        List<VehicleImpress> list = tmVhcVehicleMapper.getColor();
        // 2：天窗，3：左右舵，4：高亮膜，5：EV，6：计划类型
        List<VehicleImpress> featureList = tmVhcVehicleMapper.getFeatureItem();
        featureList.forEach(e -> {
            if (e.getValue() != null && !"".equals(e.getValue())) {
                if (SKYLIGHT.equals(e.getType())) {
                    e.setType("2");
                    list.add(e);
                }
//                else if (STEER.equals(e.getType())) {
//                    e.setType("3");
//                    list.add(e);
//                } else if (HIGH_BRIGHT_FILM.equals(e.getType())) {
//                    e.setType("4");
//                    list.add(e);
//                } else if (EV.equals(e.getType())) {
//                    e.setType("5");
//                    list.add(e);
//                }

            }
        });
        List<VehicleImpress> vehicleTypeList = tmVhcVehicleMapper.getVehicleType();
        list.addAll(vehicleTypeList);
        return list;
    }

    @Override
    public String isPsOrWsBody(String vin) {
        //查询涂装10点过点信息
        Integer tCount = tmVhcVehicleMapper.findCountAtPointByVin("TZ11_10", vin.trim());
        Integer hCount = tmVhcVehicleMapper.findCountAtPointByVin("HZ11_10", vin.trim());
        if (hCount == 0) {
            return "unKnow";
        } else if (hCount == 1 && tCount == 0) {
            return "ws";
        } else if (hCount == 1 && tCount == 1) {
            return "ps";
        }
        return "unKnow";
    }

    @Override
    public List<OnLineMakeVehicle> onLineMakeByPoint(String point,String vin) {
        return tmVhcVehicleMapper.onLineMakeByPoint(point,vin);
    }

    @Override
    public List<VehicleDetails> getVehicleDetails(VehicleDetails vehicleDetails) {
        return tmVhcVehicleMapper.findVehicleDetails(vehicleDetails);
    }

    @Override
    public List<SysCodeVo> getVehicleColorConfig() {
        return tmVhcVehicleMapper.findVehicleColorConfig();
    }

    @Override
    public List<SysCodeVo> getVehicleType() {
        return tmVhcVehicleMapper.findVehicleType();
    }
}
